package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.DataStatus;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/2/15 19:21
 */
public class KnowlegeDataStatusDialogFragment extends android.support.v4.app.DialogFragment {
  protected static final String EXTRA_DATA_STATUS =
      "com.isunland.managesystem.ui.EXTRA_DATA_STATUS";
  private int[] choiceIds = new int[] {
      R.string.all, R.string.draft, R.string.already_submit, R.string.checkapprovve, R.string.abort,
      R.string.already_cacle
  };
  private String[] choiceStrings = new String[choiceIds.length];

  @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getChoiceName(), 0,
        new DialogInterface.OnClickListener() {
          @Override public void onClick(DialogInterface dialog, int which) {

            String dataStatus;
            switch (which) {
              case 0:
                dataStatus = "";
                break;
              case 1:
                dataStatus = DataStatus.NEW;
                break;
              case 2:
                dataStatus = DataStatus.SUBMIT;
                break;
              case 3:
                dataStatus = DataStatus.PUBLIS;
                break;
              case 4:
                dataStatus = DataStatus.NEWBACK;
                break;
              case 5:
                dataStatus = DataStatus.ORDER_CANCEL;
                break;
              default:
                dataStatus = "";
                break;
            }

            if (getTargetFragment() == null) return;

            CustomerDialog customerDialog = new CustomerDialog(getChoiceName()[which], dataStatus);
            Intent i = new Intent();
            i.putExtra(EXTRA_DATA_STATUS, customerDialog);
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, i);

            dialog.dismiss();
          }
        }).create();
  }

  private String[] getChoiceName() {
    for (int i = 0; i < choiceIds.length; i++) {

      choiceStrings[i] = getResources().getString(choiceIds[i]);
    }

    return choiceStrings;
  }
}
